package com.jia.lidao.ui.personal;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jia.lidao.Constans;
import com.jia.lidao.R;
import com.jia.lidao.ui.BaseFragment;
import com.jia.lidao.ui.personal.adapter.TabAdapter;
import com.jia.lidao.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jia on 17/12/16.
 */

public class OrderListFragment extends BaseFragment {

    private static final String TYPE = "type";

    private TabLayout tabLayout;

    private ViewPager viewPager;

    private TabAdapter adapter;

    private List<Fragment> fragments;



    public static OrderListFragment newInstance(int type) {
        OrderListFragment orderListFragment = new OrderListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(TYPE, type);
        orderListFragment.setArguments(bundle);
        return orderListFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_orderlist, null);
        tabLayout = (TabLayout) view.findViewById(R.id.tab_essence);
        viewPager = (ViewPager) view.findViewById(R.id.fr_viewpager);
        LogUtil.printJ("oncreateview" + this.toString());
        initView();
        initData();
        return view;
    }


    private void initView() {
        fragments = new ArrayList<>();
        String[] titles=null;
        if (getArguments().getInt(TYPE) == 0) {
            titles = getResources().getStringArray(R.array.order_tab3);
            fragments.add(ContentFragment.newInstance(0, 0));
            fragments.add(ContentFragment.newInstance(0, 1));
            fragments.add(ContentFragment.newInstance(0, 2));
            fragments.add(ContentFragment.newInstance(0, 3));
            fragments.add(ContentFragment.newInstance(0, 4));
            fragments.add(ContentFragment.newInstance(0, 5));
        }else{
            titles = getResources().getStringArray(R.array.order_tab2);
            fragments.add(ContentFragment.newInstance(Constans.ORDERSEND, 0));
            fragments.add(ContentFragment.newInstance(Constans.ORDERSEND, 1));
            fragments.add(ContentFragment.newInstance(Constans.ORDERSEND, 2));
            fragments.add(ContentFragment.newInstance(Constans.ORDERSEND, 3));
            fragments.add(ContentFragment.newInstance(Constans.ORDERSEND, 4));
        }
        adapter = new TabAdapter(getChildFragmentManager(), fragments, titles);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);
        viewPager.setOffscreenPageLimit(5);
        tabLayout.setupWithViewPager(viewPager);
    }


    private void initData() {
    }


}
